﻿using StoreProject.DAL;
using StoreProject.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StoreProject.BLL
{
    public class BoxNumBLL
    {
        private readonly BoxNumDAL _dal = new BoxNumDAL();

        public bool Insert(BoxNumEntity model)
        {
            bool res = false;
            int? result = _dal.Insert(model);
            if (result != null)
                res = (int)result > 0;
            return res;
        }

        public bool InsertOrUpdate(BoxNumEntity model)
        {
            bool res = false;
            int? result = 0;
            if (_dal.IsExists(model.Id))
            {
                _dal.Update(model);
            }
            else
            {
                _dal.Insert(model);
            }
            if (result != null)
                res = (int)result > 0;
            return res;
        }

        public bool Update(BoxNumEntity model)
        {
            bool res = false;
            int result = _dal.Update(model);
            res = (int)result > 0;
            return res;
        }

        public bool Delete(string id)
        {
            bool res = false;
            int result = _dal.Delete(id);
            res = (int)result > 0;
            return res;
        }

        public bool Delete(BoxNumEntity model)
        {
            bool res = false;
            int result = _dal.Delete(model);
            res = (int)result > 0;
            return res;
        }

        public BoxNumEntity Get(string id)
        {
            return _dal.Get(id);
        }

        public IEnumerable<BoxNumEntity> GetList()
        {
            return _dal.GetList();
        }

        public IEnumerable<BoxNumEntity> GetListEx()
        {
            return _dal.GetListEx();
        }

        public IEnumerable<BoxNumEntity> GetListByWhere(string orderId)
        {
            return _dal.GetListByWhere(string.Format("OrderId='{0}'", orderId));
        }
        public int DeleteAll()
        {
            return _dal.DeleteAll();
        }
    }
}
